package com.example.sixteen.jt.lib;

public class Reader {

    public static final int SUCCESS = 0;

    static {
        String os = System.getProperty("os.name");
        String dir = System.getProperty("user.dir");
        System.out.println(os);
        System.out.println(System.getProperty("user.dir"));
        if (os.startsWith("Windows")) {
            System.load(dir + "\\SixteenJT.dll");
        } else {
            System.load(dir + "/libSixteenJT.so");
        }
    }

    private long handle;

    private String ip;

    protected void onAlive() {
        if (listener != null) {
            listener.onAlive(ip);
        }
    }

    protected void onInventory(String epc, int ant, int rssi) {
        if (listener != null) {
            listener.onInventory(ip, epc, ant, rssi);
        }
    }

    protected void onStop() {
        if (listener != null) {
            listener.onStop(ip);
        }
    }

    private OnReaderListener listener;

    public void setOnReaderListener(OnReaderListener listener) {
        this.listener = listener;
    }

    public interface OnReaderListener {
        /**
         * 心跳
         */
        void onAlive(String ip);

        /**
         * 盘点结果
         */
        void onInventory(String ip, String epc, int ant, int rssi);

        /**
         * 盘点结束
         */
        void onStop(String ip);
    }

    public native int connect(String ip, int port);

    public native int disconnect();

    public native int inventory(int times);

    public native int light(byte[] epc, int len);

    public native int setAnt(JTAnt[] ants);

    public native int getAnt(JTAnt[] ants);

    /**
     * 同时点亮多个发光标签
     * @param marks
     * @param times
     * @return
     */
    public native int startLightMulti(SelMark[] marks, int times);

    /**
     * 停止点亮多个发光标签
     * @return
     */
    public native int stopLightMulti();
}
